package com.mechat.common.chat.controller;

import com.mechat.common.chat.dao.MessageDao;
import com.mechat.common.chat.domain.entity.Message;
import com.mechat.common.common.domain.vo.resp.ApiResult;
import com.mechat.common.common.domain.vo.resp.IdRespVO;
import com.mechat.transaction.service.MQProducer;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/capi/test/public")
public class TestController {
    @Autowired
    private MQProducer mqProducer;

    @Autowired
    private MessageDao messageDao;

    @PostMapping("/secureInvoke")
    @ApiOperation("本地消息列表")
    @Transactional
    public ApiResult<IdRespVO> secureInvoke(String msg) {
        Message build = Message.builder()
                .fromUid(20000L)
                .type(1)
                .content(msg)
                .roomId(1L)
                .status(0)
                .build();
        messageDao.save(build);
        mqProducer.sendSecureMsg("test-topic", msg, msg);
        return ApiResult.success();
    }
}
